package com.test.exam.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.test.exam.commons.PageHelper;
import com.test.exam.dao.SubjectDao;
import com.test.exam.domain.Subject;

@Service
public class SubjectService {
	private final int SUBJECT_ROW_PER_PAGE = 3;
	
	@Autowired
	private SubjectDao subjectDao;
	
	// end page
	public int getEndPage(){
		int count = subjectDao.getSubjectCount();
		if(count == 0){
			return 0;
		}
		return (int)(Math.ceil((float)count/(float)SUBJECT_ROW_PER_PAGE));
	}
	
	// 페이지 과목 목록
	public List<HashMap> getAllSubjectsByCurrentPage(int currentPage){
		PageHelper pageHelper = new PageHelper();
		pageHelper.setRowPerPage(SUBJECT_ROW_PER_PAGE);
		pageHelper.setStartRow(currentPage);
		return subjectDao.getAllSubjectsByCurrentPage(pageHelper);
	}
	
	// 전체 목록
	public List<HashMap> getAllSubjects(){
		return subjectDao.getAllSubjects();
	}
	// 과목 추가
	public int addSubject(Subject subject){
		return subjectDao.addSubject(subject);
	}
	
	
}










